
// 读取cookie的通用函数
function getCookie(k){
	let result = {}
	let arr = document.cookie.split("; ");
	arr.forEach(item=>{
		let key = item.split("=")[0];
		let value = item.split("=")[1];
		result[key] = value;
	})

	if(!k){
		return result;
	}
	return result[k];
}

// 设置cookie的通用函数
function setCookie(key,value,expires){
	if(typeof expires === "object"){
		document.cookie = `${key}=${value};expires=${expires}`
	}
	if(typeof expires === "number"){
		let date = new Date();
		date.setDate(date.getDate() + expires);
		document.cookie = `${key}=${value};expires=${date}`
	}
}

// 删除cookie
function removeCookie(key){
	let date = new Date("1970-01-01");
	document.cookie = `${key}=1;expires=${date}`
}